package com.dinghui.mybatis.common;

import com.dinghui.mybatis.constant.HttpStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private T result;

    public ResponseResult() { }

    public ResponseResult(T result) {
        this.code = HttpStatus.SUCCESS;
        this.result = result;
    }

    public ResponseResult(int code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static ResponseResult success()
    {
        return ResponseResult.success("操作成功");
    }

    public static ResponseResult success(String msg)
    {
        return new ResponseResult(HttpStatus.SUCCESS, msg, null);
    }

    public static ResponseResult success(Object data)
    {
        return new ResponseResult(HttpStatus.SUCCESS, "操作成功", data);
    }

    public static ResponseResult success(String msg,Object data)
    {
        return new ResponseResult(HttpStatus.SUCCESS, msg, data);
    }

    public static ResponseResult error()
    {
        return ResponseResult.error("操作失败");
    }

    public static ResponseResult error(String msg)
    {
        return new ResponseResult(HttpStatus.ERROR, msg, null);
    }

    public static ResponseResult error(Object data)
    {
        return new ResponseResult(HttpStatus.ERROR, "操作失败", data);
    }

    public static ResponseResult error(int code,String msg)
    {
        return new ResponseResult(code, msg, null);
    }

    public static ResponseResult error(String msg,Object data)
    {
        return new ResponseResult(HttpStatus.ERROR, msg, data);
    }

    public static ResponseResult toResult(int result)
    {
        return result > 0 ?  ResponseResult.success() : ResponseResult.error();
    }
    public static ResponseResult toResult(int result,Object data)
    {
        return result > 0 ?  ResponseResult.success("操作成功",data) : ResponseResult.error();
    }
    public static ResponseResult notLogin()
    {
    	 return new ResponseResult(HttpStatus.NOT_LOGIN, "未登录",null);
    }





}
